﻿<UserControl x:Class="ScrumFactory.Projects.Burndown"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition" 
             
             xmlns:props="clr-namespace:ScrumFactory.Projects.Properties"
             
             xmlns:visualization="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
             xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
             xmlns:chartPrmtvs="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
             
             SF_Comp:CommandBehavior.RoutedEventName="Loaded"
             SF_Comp:CommandBehavior.TheCommandToRun="{Binding OnLoadCommand}"

             x:Name="thisView"
             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500">
    <UserControl.Resources>

        <Style x:Key="SprintToolTip" TargetType="{x:Type ToolTip}">
            <Setter Property="OverridesDefaultStyle" Value="true"/>            
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToolTip">
                        <Border 
                            Background="{StaticResource ToolTipBackgroundBrush}"
                            BorderBrush="{StaticResource ToolTipBorderBrush}"
                            CornerRadius="7" HorizontalAlignment="Center" VerticalAlignment="Top" Padding="5" BorderThickness="1">                            
                            <ContentPresenter />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <Style TargetType="charting:Chart">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="charting:Chart">
                        <Grid Background="{TemplateBinding Background}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <visualization:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" Margin="1"/>
                            
                            <Grid Grid.Row="1" Margin="5,0,5,0" Background="{TemplateBinding Background}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <chartPrmtvs:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}" Background="{TemplateBinding Background}">
                                    <Grid Canvas.ZIndex="-1" Style="{TemplateBinding PlotAreaStyle}" Background="{TemplateBinding Background}"/>
                                    <Border Canvas.ZIndex="10" BorderThickness="0"  />
                                </chartPrmtvs:EdgePanel>
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="BurndownToggleButton" TargetType="{x:Type ToggleButton}">                        
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border Style="{StaticResource MouseOverBorder}">
                            <Border x:Name="border" Margin="3"
                                ToolTip="{TemplateBinding ToolTip}"
                                Background="LightGray"  BorderBrush="Gray" BorderThickness="1" CornerRadius="2" MinWidth="20">
                                <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center">
                                    <ContentPresenter.Resources>
                                        <Style TargetType="{x:Type TextBlock}">
                                            <Setter Property="Foreground" Value="Gray"/>
                                            <Setter Property="FontFamily" Value="Segoe UI"/>
                                            <Setter Property="FontSize" Value="{StaticResource SmallFontSize}"/>
                                        </Style>
                                    </ContentPresenter.Resources>
                                </ContentPresenter>
                            </Border>
                        </Border>                        
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="border" Property="Background" Value="DarkGray"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        
        
        <charting:Chart     
            Grid.Row="0"            
            Title="{x:Static props:Resources.Project_Burndown}"                 
            Background="Transparent"
            BorderThickness="0">
                        
            <charting:Chart.Axes>                                
                <charting:DateTimeAxis Orientation="X"  IntervalType="Days"   >
                    <charting:DateTimeAxis.AxisLabelStyle>
                        <Style TargetType="charting:AxisLabel">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="charting:AxisLabel">
                                        <TextBlock Text="{Binding StringFormat='{}{0:dd/M}'}" FontSize="8"/>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </charting:DateTimeAxis.AxisLabelStyle>
                </charting:DateTimeAxis>                
                <charting:LinearAxis Minimum="0" Orientation="Y" ShowGridLines="True">
                    <charting:LinearAxis.GridLineStyle>
                        <Style TargetType="{x:Type Line}">
                            <Setter Property="Stroke" Value="LightGray"/>
                        </Style>
                    </charting:LinearAxis.GridLineStyle>
                </charting:LinearAxis>               
            </charting:Chart.Axes>
            <charting:Chart.TitleStyle>
                <Style TargetType="Control">
                    <Setter Property="Visibility" Value="Collapsed" />
                </Style>
            </charting:Chart.TitleStyle>
            <charting:Chart.LegendStyle>
                <Style TargetType="Control">
                    <Setter Property="Width"  Value="0"/>
                    <Setter Property="Height" Value="0"/>
                </Style>
            </charting:Chart.LegendStyle>
            <charting:Chart.Series>

                <charting:AreaSeries                                                                             
                    ItemsSource="{Binding ActualHoursAhead}"                    
                    IndependentValuePath="Date"
                    DependentValuePath="TotalHours">
                    <charting:AreaSeries.DataPointStyle>
                        <Style TargetType="Control">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate/>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Background" Value="LightGray"/>
                        </Style>
                    </charting:AreaSeries.DataPointStyle>
                </charting:AreaSeries>

                <charting:AreaSeries                                     
                    ItemsSource="{Binding ActualHours}"
                    IndependentValuePath="Date"
                    DependentValuePath="TotalHours">
                    <charting:AreaSeries.DataPointStyle>
                        <Style TargetType="Control">
                            <Setter Property="Background">
                                <Setter.Value>
                                    <SolidColorBrush Color="{StaticResource Blue3Color}" Opacity="0.8"/>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Width" Value="10"/>
                            <Setter Property="Height" Value="10"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type charting:AreaDataPoint}">
                                        <Ellipse        
                                                Cursor="Help"
                                                StrokeThickness="3" Width="10" Height="10">
                                            <Ellipse.Fill>
                                                <SolidColorBrush Color="White"/>
                                            </Ellipse.Fill>
                                            <Ellipse.Stroke>
                                                <SolidColorBrush Color="{StaticResource Blue4Color}"/>
                                            </Ellipse.Stroke>
                                            <Ellipse.ToolTip>
                                                <ToolTip Style="{StaticResource SprintToolTip}">
                                                    <StackPanel>
                                                        <TextBlock Text="{x:Static props:Resources.Today}" FontWeight="Bold"/>
                                                        <TextBlock Text="{Binding Date, StringFormat={x:Static props:Resources.dd_MMM}}"/>
                                                        <TextBlock Text="{Binding TotalHours, StringFormat={x:Static props:Resources.N_hrs}}"/>
                                                    </StackPanel>
                                                </ToolTip>
                                            </Ellipse.ToolTip>
                                        </Ellipse>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsToday}" Value="False">
                                    <Setter Property="Width" Value="0"/>
                                    <Setter Property="Height" Value="0"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </charting:AreaSeries.DataPointStyle>
                    <charting:AreaSeries.PathStyle>
                        <Style TargetType="Path">
                            <Setter Property="StrokeThickness" Value="2" />
                            <Setter Property="Stroke">
                                <Setter.Value>
                                    <SolidColorBrush Color="{StaticResource Blue4Color}"/>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </charting:AreaSeries.PathStyle>
                </charting:AreaSeries>

      

                <charting:LineSeries                    
                    ItemsSource="{Binding PlannedHours}"                                        
                    IndependentValuePath="Date"                    
                    DependentValuePath="TotalHours">                      
                    <charting:LineSeries.PolylineStyle>
                        <Style TargetType="{x:Type Polyline}">
                            <Setter Property="StrokeThickness" Value="3"/>
                        </Style>
                    </charting:LineSeries.PolylineStyle>
                    <charting:LineSeries.DataPointStyle>
                        <Style TargetType="Control">    
                            <Setter Property="Background" Value="Red"/>
                            <Setter Property="Width" Value="10"/>
                            <Setter Property="Height" Value="10"/>                                                          
                            <Setter Property="Template">                                
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type charting:LineDataPoint}">
                                        <Ellipse        
                                                Cursor="Help" x:Name="ellipse"
                                                Stroke="Red" StrokeThickness="3" Width="10" Height="10" Fill="White">
                                            <Ellipse.ToolTip>
                                                <ToolTip Style="{StaticResource SprintToolTip}">
                                                    <StackPanel>
                                                        <TextBlock x:Name="tooltip" FontWeight="Bold">
                                                            <TextBlock.Style>
                                                                <Style>
                                                                    <Setter Property="TextBlock.Text" Value="{Binding SprintNumber, StringFormat={x:Static props:Resources.sprint_N}}"/>
                                                                    <Style.Triggers>
                                                                        <DataTrigger Binding="{Binding IsLastSprint}" Value="True">
                                                                            <Setter Property="TextBlock.Text" Value="{x:Static props:Resources.project_end}"/>
                                                                        </DataTrigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </TextBlock.Style>
                                                        </TextBlock>
                                                        <TextBlock Text="{Binding Date, StringFormat='{}{0:dd/MMM}'}"/>
                                                        <TextBlock Text="{Binding TotalHours, StringFormat={x:Static props:Resources.N_hrs}}"/>
                                                    </StackPanel>                                                    
                                                </ToolTip>
                                            </Ellipse.ToolTip>
                                        </Ellipse>
                                        <ControlTemplate.Triggers>
                                            <DataTrigger Binding="{Binding IsToday}" Value="True">
                                                <Setter TargetName="tooltip" Property="TextBlock.Text" Value="{x:Static props:Resources.Today}"/>
                                                <Setter TargetName="ellipse" Property="Ellipse.Stroke">
                                                    <Setter.Value>
                                                        <SolidColorBrush Color="{StaticResource Orange2Color}"/>
                                                    </Setter.Value>
                                                </Setter> 
                                            </DataTrigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>                                    
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </charting:LineSeries.DataPointStyle>
                </charting:LineSeries>

                
                
            </charting:Chart.Series>

        </charting:Chart>
        <ContentControl           
            Grid.Row="0"
            HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Style="{StaticResource LoadingAnimationContent}"/>

        <StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal">
            <TextBlock Width="100" TextAlignment="Center">
                <TextBlock
                    Foreground="{StaticResource LabelBrush}" HorizontalAlignment="Center"
                    FontFamily="{StaticResource WideFont}" FontSize="40" FontWeight="Bold"
                    Text="{Binding WalkedPct, StringFormat='{}{0:0}'}"/>
                <LineBreak/>
                <TextBlock
                    Foreground="{StaticResource LabelBrush}" HorizontalAlignment="Center"
                    FontSize="{StaticResource SmallFontSize}" FontWeight="Bold"
                    TextWrapping="Wrap"
                    Text="{x:Static props:Resources.walked}"/>
            </TextBlock>
            
            <TextBlock 
                Style="{StaticResource IndicatorTextBlock}"
                DataContext="{Binding DeadlinePositionStatus}" Width="100" TextAlignment="Center"
                HorizontalAlignment="Center">
                <TextBlock
                    HorizontalAlignment="Center" TextAlignment="Center"
                    FontFamily="{StaticResource WideFont}" FontSize="40" FontWeight="Bold"
                    Text="{Binding ElementName=thisView, Path=DataContext.DeadlinePosition, StringFormat='{}{0:0}'}"/>
                <LineBreak/>
                <TextBlock
                    HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap"
                    FontSize="{StaticResource SmallFontSize}" FontWeight="Bold"
                    Text="{Binding ElementName=thisView, Path=DataContext.DeadlinePositionLabel}"/>                    
            </TextBlock>
            
            
        </StackPanel>
        

        <StackPanel
            x:Name="controls"
            Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
            <ToggleButton
                Content="{x:Static props:Resources.C}"
                ToolTip="{x:Static props:Resources.C_tooltip}"
                Command="{Binding ChangePlanningCurveCommand}" CommandParameter="CURRENT_PLANNING"> 
                <ToggleButton.Style>
                    <Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource BurndownToggleButton}">
                        <Setter Property="ToggleButton.IsChecked" Value="False"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding PlanningCurveMode}" Value="CURRENT_PLANNING">
                                <Setter Property="ToggleButton.IsChecked" Value="True"/>
                            </DataTrigger>
                        </Style.Triggers>                            
                    </Style>
                </ToggleButton.Style>
            </ToggleButton>
            <ToggleButton
                Content="{x:Static props:Resources.P}"
                ToolTip="{x:Static props:Resources.P_tooltip}"
                Command="{Binding ChangePlanningCurveCommand}" CommandParameter="PROPOSAL_PLANNING">
                <ToggleButton.Style>
                    <Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource BurndownToggleButton}">
                        <Setter Property="ToggleButton.IsChecked" Value="False"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding PlanningCurveMode}" Value="PROPOSAL_PLANNING">
                                <Setter Property="ToggleButton.IsChecked" Value="True"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ToggleButton.Style>
            </ToggleButton>
            <ToggleButton
                Content="{x:Static props:Resources.F}"
                ToolTip="{x:Static props:Resources.F_tooltip}"
                Command="{Binding ChangePlanningCurveCommand}" CommandParameter="FIRST_PLANNING">
                <ToggleButton.Style>
                    <Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource BurndownToggleButton}">
                        <Setter Property="ToggleButton.IsChecked" Value="False"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding PlanningCurveMode}" Value="FIRST_PLANNING">
                                <Setter Property="ToggleButton.IsChecked" Value="True"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ToggleButton.Style>
            </ToggleButton>
        </StackPanel>
                        
        
    </Grid>
    
   
    
    
</UserControl>
